package com.distribute.application.api.utils.mobile;

import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;


public class TextMessageSender {
	private TextMessageSender(){}
	private static TextMessageSender textMessage = null;
	
	public static synchronized TextMessageSender getInstance(){
		if(textMessage == null)
			textMessage = new TextMessageSender();
		return textMessage;
	}
	public String sendMessage(TextMessageEntity messageEntity, String msg, String phone) throws HttpException, IOException{
		HttpClient httpClient = new HttpClient();
		PostMethod postMethod = new PostMethod(messageEntity.getMessageServer());
		postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8;");
		postMethod.setRequestHeader("Accept", "application/json;charset=utf-8;");
		postMethod.setParameter("apikey", "61a91bf5c7a50a4f333df35229bcc554");
		postMethod.setParameter("text", msg);
		postMethod.setParameter("mobile", phone);
		
		postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
		String response = "";

		httpClient.executeMethod(postMethod);
		response = postMethod.getResponseBodyAsString();

		return response;
	}
}
